package net.leieuncretino.beta.prefixtree;

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.FileOutputStream;
import java.io.FileReader;

/** External use, to create dictionary
 * 
 * @author g.terenziani
 *
 */
public class CreaDizionario implements TrieConst {
	private static void readFileIntoTrie(String dictFile, Trie trie,
			int mask) {

			try {
				BufferedReader br = new BufferedReader(new FileReader(dictFile));
				String line;
				while((line = br.readLine()) != null) {
					//System.out.println(line);
					trie.addWord(line,mask);
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}

		public static void main(String [] Args) {

			if(Args.length < 5) {
				System.out.println("Usage: java -jar dicttool endict itdict frdict esdict outfile");
				System.exit(1);
			}

			Trie outTrie = new Trie();

			readFileIntoTrie(Args[0],outTrie, TrieConst.EN_WORD_BIT);
			readFileIntoTrie(Args[1],outTrie, TrieConst.IT_WORD_BIT);
			readFileIntoTrie(Args[2],outTrie, TrieConst.FR_WORD_BIT);
			readFileIntoTrie(Args[3],outTrie, TrieConst.ES_WORD_BIT);
			
			try {
				FileOutputStream of = new FileOutputStream(Args[4],false);
				outTrie.write(new DataOutputStream(of));
			} catch (Exception e) {
				e.printStackTrace();
			}

		}

}
